//
//  ViewController.m
//  TomCat
//
//  Created by student on 16/2/19.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIButton *eatBtn;
@property (weak, nonatomic) IBOutlet UIButton *drinkBtn;
@property (weak, nonatomic) IBOutlet UIButton *fartBtn;
@property (weak, nonatomic) IBOutlet UIButton *pieBtn;
@property (weak, nonatomic) IBOutlet UIButton *scratchBtn;

@property (weak, nonatomic) IBOutlet UIButton *cymbalBtn;

@end

@implementation ViewController

- (void)viewDidLoad
{
    
[super viewDidLoad];

    
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
    {
        
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)eat:(UIButton *)sender
{
    NSMutableArray *mArr = [[NSMutableArray alloc] init];
    for (int i=0; i<=39; i++)
    {
        NSString *picName = [NSString stringWithFormat:@"eat_%i.png",i];
        UIImage *image = [UIImage imageNamed:picName];
        [mArr addObject:image];
    }
    self.imageView.animationRepeatCount = 1;
    self.imageView.animationDuration = 5;
    self.imageView.animationImages = mArr;

    if(self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
        [self.eatBtn setTitle:@"跳" forState:UIControlStateNormal];
    }
    else
    {
        [self.imageView startAnimating];
        [self.eatBtn setTitle:@"停" forState:UIControlStateNormal];
    }

   }

- (IBAction)drink:(UIButton *)sender
{
    NSMutableArray *mArr = [[NSMutableArray alloc] init];
    for (int i=0; i<=80; i++)
    {
        NSString *picName = [NSString stringWithFormat:@"drink_%i.png",i];
        UIImage *image = [UIImage imageNamed:picName];
        [mArr addObject:image];
    }
    self.imageView.animationRepeatCount = 1;
    self.imageView.animationDuration = 5;
    self.imageView.animationImages = mArr;
    
    if(self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
        [self.drinkBtn setTitle:@"跳" forState:UIControlStateNormal];
    }
    else
    {
        [self.imageView startAnimating];
        [self.drinkBtn setTitle:@"停" forState:UIControlStateNormal];
    }
    

   }

- (IBAction)fart:(UIButton *)sender
{
    NSMutableArray *mArr = [[NSMutableArray alloc] init];
    for (int i=0; i<=27; i++)
    {
        NSString *picName = [NSString stringWithFormat:@"fart_%i.png",i];
        UIImage *image = [UIImage imageNamed:picName];
        [mArr addObject:image];
    }
    self.imageView.animationRepeatCount = 1;
    self.imageView.animationDuration = 5;
    self.imageView.animationImages = mArr;
    
    if(self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
        [self.fartBtn setTitle:@"跳" forState:UIControlStateNormal];
    }
    else
    {
        [self.imageView startAnimating];
        [self.fartBtn setTitle:@"停" forState:UIControlStateNormal];
    }
    

   }

- (IBAction)pie:(UIButton *)sender
{
    NSMutableArray *mArr = [[NSMutableArray alloc] init];
    for (int i=0; i<=23; i++)
    {
        NSString *picName = [NSString stringWithFormat:@"pie_%i.png",i];
        UIImage *image = [UIImage imageNamed:picName];
        [mArr addObject:image];
    }
    self.imageView.animationRepeatCount = 1;
    self.imageView.animationDuration = 5;
    self.imageView.animationImages = mArr;
    
    if(self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
        [self.pieBtn setTitle:@"跳" forState:UIControlStateNormal];
    }
    else
    {
        [self.imageView startAnimating];
        [self.pieBtn setTitle:@"停" forState:UIControlStateNormal];
    }
    

   }

- (IBAction)scratch:(UIButton *)sender
{
    NSMutableArray *mArr = [[NSMutableArray alloc] init];
    for (int i=0; i<=55; i++)
    {
        NSString *picName = [NSString stringWithFormat:@"scratch_%i.png",i];
        UIImage *image = [UIImage imageNamed:picName];
        [mArr addObject:image];
    }
    self.imageView.animationRepeatCount = 1;
    self.imageView.animationDuration = 5;
    self.imageView.animationImages = mArr;
    
    if(self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
        [self.scratchBtn setTitle:@"跳" forState:UIControlStateNormal];
    }
    else
    {
        [self.imageView startAnimating];
        [self.scratchBtn setTitle:@"停" forState:UIControlStateNormal];
    }
    

    }

- (IBAction)cymbal:(UIButton *)sender
{
    NSMutableArray *mArr = [[NSMutableArray alloc] init];
    for (int i=0; i<=12; i++)
    {
        NSString *picName = [NSString stringWithFormat:@"cymbal_%i.png",i];
        UIImage *image = [UIImage imageNamed:picName];
        [mArr addObject:image];
    }
    self.imageView.animationRepeatCount = 1;
    self.imageView.animationDuration = 5;
    self.imageView.animationImages = mArr;
    
    if(self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
        [self.cymbalBtn setTitle:@"跳" forState:UIControlStateNormal];
    }
    else
    {
        [self.imageView startAnimating];
        [self.cymbalBtn setTitle:@"停" forState:UIControlStateNormal];
    }
    

   }
@end
